
var imgview = function(srcarr,index){
	if($('.imgview').length!=0){
		$('.imgview').show().find('img').remove();
		$('.imgview .left,.imgview .right').show();
	}else{
		$('body').append('<div class="imgview"><div class="left"></div><div class="right"></div><div class="CLOSE"></div></div>');
	}
	$('.CLOSE').unbind().bind('click',function(){
		$('.imgview').hide();
	});
	var self = this;
	this.srcarr = srcarr;
	this.leng = this.srcarr.length;
	var img = new Image();
	img.onload = function(){
		var a = show({w:this.width,h:this.height}),showimg;
		showimg = '<img src="'+self.srcarr[index]+'" width="'+a.w+'" height="'+a.h+'" style="margin-left:'+-a.w/2+'px;margin-top:'+-a.h/2+'px;">';
		if($('.imgview img')){
			$('.imgview img').remove();
		}
		$('.imgview').append(showimg);
	};
	img.src = this.srcarr[index];
	$('.imgview .right').bind('click',function(){
		$(this).unbind();
		imgview(srcarr,index+1);
	});
	$('.imgview .left').bind('click',function(){
		$(this).unbind();
		imgview(srcarr,index-1);
	});
	if(index==0&&index!=this.leng-1){
		$('.imgview .left').hide().unbind();
	}else if(index!=0&&index==this.leng-1){
		$('.imgview .right').hide().unbind();
	}else if(index==0&&index==this.leng-1){
		$('.imgview .left').hide().unbind();
		$('.imgview .right').hide().unbind();
	}else{
		$('.imgview .left').show();
		$('.imgview .right').show();
	}
	var show = function(a){
		var w = $(window).width(),h = $(window).height(),bi,BI;
		bi = w/h;
		BI = a.w/a.h;
		if(a.w>w&&a.w/a.h>bi){
			a.w = w;
		}else if(a.h>h&&a.w/a.h<bi){
			a.w = parseInt(a.w*h/a.h);
		}
		a.h = a.w/BI;
		return a;
	};
};